<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
  </head>
  <body>
    <script>
      const _searchStrIndexOf = (str, target) => {
        // 补全代码
        /* 方法一： */
        // var arr = str.split(target)
        // return arr.length - 1
        /* 方法二： */
        var index = str.indexOf(target)
        let num = 0
        while (index !== -1) {
          index = str.indexOf(target, index + 1)
          num++
        }
        return num
      }
      console.log(_searchStrIndexOf('abcabc', 'abc'))
    </script>
  </body>
</html>
